package com.yanyilu.basing.service.impl;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectRequest;
import com.yanyilu.basing.service.IUploadService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;

@Service
public class UpladServiceImpl implements IUploadService {
    @Value("${accessKeyId}")
    private String accessKeyId;

    @Value("${accessKeySecret}")
    private String accessKeySecret;

    @Value("${endpoint}")
    private String endpoint;

    @Value("${downLoadUrl}")
    private String downLoadUrl;

    //上传阿里云
    public String toOSS(String fileName,String path){
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        PutObjectRequest putObjectRequest = new PutObjectRequest("demoee", "basing/" + fileName, new File(path));
        ossClient.putObject(putObjectRequest);
        ossClient.shutdown();
        return downLoadUrl+fileName;
    }
}
